#include "stdafx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
void calc_macd(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double*fpEMA1=dataCalc[4],*fpEMA2=dataCalc[5];
	double*DIF=dataCalc[0],*DEA=dataCalc[1],*BAR=dataCalc[2];
	double*pcdClose=dataCalc[6];
	double seedPrice(__price_seed__[decNum]);
	for(i=0;i<numCalc;++i)
		pcdClose[i] = paData[i].ClosePx/seedPrice;

	memcpy(fpEMA1,pcdClose,numCalc*sizeof(double));
	memcpy(fpEMA2,pcdClose,numCalc*sizeof(double));

	UMyCalc_EMA(fpEMA1,numCalc,pFormula->infoParam[0].nowValue);
	UMyCalc_EMA(fpEMA2,numCalc,pFormula->infoParam[1].nowValue);
	UMyCalc_SUB(DIF,fpEMA1,fpEMA2,numCalc);

	memcpy(DEA,DIF,numCalc*sizeof(double));
	UMyCalc_EMA(DEA,numCalc,pFormula->infoParam[2].nowValue);

	for(i=0;i<numCalc;++i)
	{
		BAR[i] = 2*(DIF[i]-DEA[i]);
	}
}
/*
DIF:EMA(CLOSE,SHORT)-EMA(CLOSE,LONG);
DEA:EMA(DIF,MID);
MACD:(DIF-DEA)*2,COLORSTICK;
*/

void calc_vmacd(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double*fpEMA1=dataCalc[4],*fpEMA2=dataCalc[5];
	double*DIF=dataCalc[0],*DEA=dataCalc[1],*BAR=dataCalc[2];

	double*pcdVolume=dataCalc[6];
	for(i=0;i<numCalc;++i)
		pcdVolume[i] = (double)paData[i].totalVolumeTrade;

	memcpy(fpEMA1,pcdVolume,numCalc*sizeof(double));
	memcpy(fpEMA2,pcdVolume,numCalc*sizeof(double));

	UMyCalc_EMA(fpEMA1,numCalc,pFormula->infoParam[0].nowValue);
	UMyCalc_EMA(fpEMA2,numCalc,pFormula->infoParam[1].nowValue);
	UMyCalc_SUB(DIF,fpEMA1,fpEMA2,numCalc);

	memcpy(DEA,DIF,numCalc*sizeof(double));
	UMyCalc_EMA(DEA,numCalc,pFormula->infoParam[2].nowValue);

	for(i=0;i<numCalc;++i)
	{
		BAR[i] = 2*(DIF[i]-DEA[i]);
	}
}
/*
DIF:EMA(VOL,SHORT)-EMA(VOL,LONG);
DEA:EMA(DIF,MID);
MACD:DIF-DEA,COLORSTICK;
*/
